/*
 * ChatUserInfoAction.java
 *
 * Created on 2007年5月17日, 上午10:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.pphome.orgmodel.action;



import com.ecomm.chat.manager.ChatUserInfoManager;
import com.ecomm.chat.pojo.ChatUserInfo;
import com.ecomm.platcore.struts.support.BusinessException;
import com.ecomm.util.Logger;
import com.ecomm.platcore.struts.StrutsEntityAction;
import com.pphome.orgmodel.manager.OrgManager;
import com.pphome.orgmodel.manager.UserManager;
import com.pphome.orgmodel.pojo.OrgInfo;
import com.pphome.orgmodel.pojo.UserInfo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * <p>Title: 易讯聊天系统</p>
 * <p>Description:
 *  易讯聊天系统
 * </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: 联合易讯 </p>
 * @author <font color='blue'>pijunliang</font> &nbsp&nbsp<a href="mailto:pijunliang@hotmail.com">pijunliang@hotmail.com</a>
 * @version 1.0
 * @since  2007年5月17日, 上午10:43
 */
public class UserAction extends StrutsEntityAction<UserInfo,UserManager> {
  private Log log = Logger.getLog(UserAction.class);
  
  private UserManager userManager =UserManager.getInstance();
  /**
   *保存 或是修改 用户信息
   *
   */
  public ActionForward saveorupdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    UserInfo object = doNewEntity(form, request);
    
    String id = request.getParameter(idName);
    // 将lazyform内容绑定到object
    initEntity(form, request, object);
    if(id != null && !id.equals("")){
      userManager.doUpdateEntity(object);
    }else{
      id =  userManager.doSaveEntity(object);
      object.setId(id);
    }
    request.setAttribute("userInfo",object);
    return mapping.findForward(SUCCESS);
  }
  /**
   *保存 或是修改 用户信息
   *
   */
  public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    UserInfo ui = userManager.getuserInfoByLoginName(username,password);
    if(ui == null ){
      return mapping.findForward("chatlogin");
    }
    request.getSession().setAttribute("userinfoSess",ui);
    request.setAttribute("userInfo",ui);
    return mapping.findForward("chathome");
  }
}

